package com.ckd.flyingtrip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.javabean.BuycarAreaBean;

import java.util.List;

public class PopWinAdapter1 extends RecyclerView.Adapter<PopWinAdapter1.MyHolder> {

    private Context context;
    private List<BuycarAreaBean.DataBean> dataBeans;
    private int anInt = 0;

    public OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public PopWinAdapter1(Context context, List<BuycarAreaBean.DataBean> dataBeans) {
        this.context = context;
        this.dataBeans = dataBeans;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_popwin_buycar_recycler1, null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {

        if (anInt == position) {
            holder.textView.setTextColor(ContextCompat.getColor(context, R.color.color_f3800f));
            holder.textView.setBackground(ContextCompat.getDrawable(context, R.color.white));
        } else {
            holder.textView.setTextColor(ContextCompat.getColor(context, R.color.color_333));
            holder.textView.setBackground(ContextCompat.getDrawable(context, R.color.color_f5));
        }

        holder.textView.setText(dataBeans.get(position).getAreaName());
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeans.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView textView;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_popwin_buycar_recycler1_textView);
        }
    }

    public void setAnInt(int anInt) {
        this.anInt = anInt;
    }
}
